import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { message } from "@/utils/message";
type Result = {
  current_page: number;
  result?: any;
  per_page?: number;
  total?: number;
};
type ResultDelete = {
  code: number;
  msg: string;
};
type ResultCreate = {
  code: number;
  msg: string;
};
type Show = {
  code: number;
  msg: string;
  result?: any;
};

/** 任务列表 */
export const taskListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/task/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 添加任务 */
export const taskStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/task/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 编辑任务 */
export const taskUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/task/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 详情任务 */
export const taskShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/task/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 删除任务 */
export const taskDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/task/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 详情任务 */
export const taskSelectApi = (data?: object) => {
  return http.request<Show>("get", baseUrlApi + "/task/select", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 批量添加任务 */
export const taskBulkStoreApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/task/bulkUpdate", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 任务类型 */
export const taskTypeSelectApi = (data?: object) => {
  return http.request<Show>("get", baseUrlApi + "/task/typeSelect", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 任务状态更新 */
export const taskUpdateStatusApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/task/updateStatus", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 类型列表 */
export const taskTypeListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/taskType/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 类型创建 */
export const taskTypeStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/taskType/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 类型修改 */
export const taskTypeUpdateApi = (params?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/taskType/update", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 类型详情 */
export const taskTypeShowApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/taskType/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 删除类型 */
export const taskTypeDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/taskType/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 类型选项 */
export const typeSelectApi = (data?: object) => {
  return http.request<Show>("get", baseUrlApi + "/taskType/select", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 任务列表树 */
export const taskListTreeApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/task/listTree", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 任务状态批量更新 */
export const bulkUpdateStatusApi = (params?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/task/bulkUpdateStatus", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
